问题1:如何在xml文件里写注释。

解决办法:如下

<!--这里写注释-->

问题2:如何通过Intent打开另一个应用软件。

解决办法:1.通过给另一个应用软件添加隐式启动方式;

g(想要启动的应用中):

<intent-filter>
    <action android:name="xxx.intent.action.MainActivity"></action>
    <category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>

(另一个应用):

Intent i=new Intent("xxx.intent.action.MainActivity");
startActivity(i);

2.通过获得想要启动的应用的包名和类名来启动应用;


Intent i=new Intent();
i.setClassName("包名","类名");
startActivity(i);

问题3:即使在AndroidManifest中设置了对联系人进行读写的权限,程序依旧不能正确进行。

问题所在:在安卓6.0(API 23)之后, 所有的权限仍然在manifest中静态声明, normal权限的在安装的时候自动授权, 而dangerous的权限需要应用明确地请求用户授权。对通讯录的操作需要获得的权限为dangerous

具体权限等级设置:(http://developer.android.com/guide/topics/manifest/permission-element.html\)

参考资料:(http://www.cnblogs.com/mengdd/p/4892856.html\)

解决办法:

在代码中先查看是否获得了所需要的权限<br>

if(checkSelfPermission(Manifest.permission.READ_CONTACTS)== PackageManager.PERMISSION_DENIED){......}

如果没有获得权限则向用户请求相应的权限

ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_CONTACTS},1);

results matching ""

    No results matching ""